import * as Koa from 'koa'
import * as onerror from 'koa-onerror'
import * as bodyparser from 'koa-bodyparser'
import * as json from 'koa-json'
import * as logger from 'koa-logger'
import * as koaStatic from 'koa-static'
import { index } from "./routes/index";
import { users } from "./routes/user";

const app = new Koa()

onerror(app)

app.use(bodyparser())
app.use(json())
app.use(logger())
app.use(koaStatic('/public'))

app.use(async (ctx, next) => {
  let start = Date.now()
  await  next()
  let ms = Date.now() - start
  console.log(`${ctx.method} ${ctx.url} - ${ms}ms`)
})

app.use(index.routes(), index.allowedMethods())
app.use(users.routes(), users.allowedMethods())

app.listen(3000)
